//
//  MHConstInline.h
// MiaoCircle
//
//Created by acgera on 2018/4/9.
//  Copyright © 2018年 acgera. All rights reserved.
//

#ifndef MHConstInline_h
#define MHConstInline_h
#import "NSString+MHSize.h"
#import "UIFont+MHExtension.h"
#import "MHHTTPService.h"
#import "MHStatusHelper.h"
#import "AXAppDelegate.h"
/// 网络图片的占位图片
static inline UIImage *MHWebImagePlaceholder(){
    return [UIImage imageNamed:@"placeholder_image"];
}


static inline UIImage *MHCircleBgPlaceHolder(){
    return [UIImage imageNamed:@"placeholder_image"];
}

/// 网络头像
//static inline UIImage *MHWebAvatarImagePlaceholder(){
//    return [UIImage imageNamed:@"DefaultProfileHead_66x66"];
//}

static inline UIImage *MHDefaultAvatar(MHDefaultAvatarType type)
{
    switch (type) {
        case MHDefaultAvatarTypeSmall:
            return [UIImage imageNamed:@"placeholder_avaterimage"];
            break;
        case MHDefaultAvatarTypeBig:
            return [UIImage imageNamed:@"placeholder_avaterimage"];
            break;
        default:
            return [UIImage imageNamed:@"placeholder_avaterimage"];
            break;
    }
}


static inline NSString *forametTagString(NSString *tagStr)
{

//    NSRange
    
//   AXAppDelegate
//    [AXAppDelegate sha]
    if ([AXAppDelegate sharedDelegate].isAuthorizationExpired) {
        return tagStr;
    }else
    {
        NSMutableString *backUpString = tagStr.mutableCopy;
        NSString *replaceString = @"";
        NSArray<NSTextCheckingResult *> *topicResults =  [[MHStatusHelper regexTopic] matchesInString:tagStr options:kNilOptions range:NSMakeRange(0, tagStr.length)];
        
        if(topicResults.count <= 0)
        {
            replaceString = tagStr;
        }else
        {
            for (NSTextCheckingResult *topic in topicResults) {
                NSRange range = topic.range;
                replaceString = [backUpString stringByReplacingOccurrencesOfString:[tagStr substringWithRange:range] withString:@""];
            }
        }
        return replaceString;
    }

}

static inline UIImage *MHNavBackGround()
{
 
  
//    [AXAppDelegat]
    NSString *deviceType = [UIDevice currentDevice].model;

    if ([deviceType isEqualToString:@"iPad"])
    {
        return  [UIImage imageNamed:@"nav_bg"];
    }else
    {
        return  [UIImage imageWithColor:[UIColor whiteColor]];
    }
    
}




static inline int MHCurretUserId()
{
    return  [MHHTTPService sharedInstance].currentUser.userId;
}
static inline BOOL isEquaalCurrentUserId(NSString *userId)
{
    return [userId isEqualToString:[NSString stringWithFormat:@"%d",MHCurretUserId()]];
}

static inline UILabel *createAttriNavTitleLable(NSString *top,NSString *bottom)
{
    UILabel *titleView = [[UILabel alloc]init];
    titleView.height = 100;
    titleView.width = 200;
    titleView.numberOfLines = 0;
    titleView.textAlignment = NSTextAlignmentCenter;
//    titleView.origin.y = 50;
    NSString *str = [NSString stringWithFormat:@"%@\n%@",top , bottom];
    // 创建一个带有属性的字符串（比如颜色属性、字体属性等文字属性）
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:str];
    [attStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:[str rangeOfString:top]];
    [attStr addAttribute:NSForegroundColorAttributeName value:MHTextColor333 range:[str rangeOfString:top]];
    [attStr addAttribute:NSFontAttributeName value:MHRegularFont_12 range:[str rangeOfString:bottom]];
    [attStr addAttribute:NSForegroundColorAttributeName value:MHTextColor333 range:[str rangeOfString:bottom]];
    titleView.attributedText = attStr;
    return titleView;
}


static inline UILabel *createAttriNavTitleLableWhitColor(NSString *top,NSString *bottom,UIColor *color)
{
    UILabel *titleView = [[UILabel alloc]init];
    titleView.height = 100;
    titleView.width = 200;
    titleView.numberOfLines = 0;
    titleView.textAlignment = NSTextAlignmentCenter;
    //    titleView.origin.y = 50;
    NSString *str;
    if (bottom.length<=0) {
         str = top;
    }else
    {
        str = [NSString stringWithFormat:@"%@\n%@",top , bottom];
    }
    
    // 创建一个带有属性的字符串（比如颜色属性、字体属性等文字属性）
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:str];
    [attStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:[str rangeOfString:top]];
    [attStr addAttribute:NSForegroundColorAttributeName value:color range:[str rangeOfString:top]];
    
    [attStr addAttribute:NSFontAttributeName value:MHRegularFont_12 range:[str rangeOfString:bottom]];
    [attStr addAttribute:NSForegroundColorAttributeName value:color range:[str rangeOfString:bottom]];
    titleView.attributedText = attStr;
    return titleView;
}

/// 配图的占位图片
static inline UIImage *MHPicturePlaceholder()
{
    return [UIImage imageNamed:@"placeholder_image"];
}


static inline bool isIPhoneX () {
//    UIUserInterfaceIdiom idiom = [UIDevice currentDevice].userInterfaceIdiom;
//    if (idiom == UIUserInterfaceIdiomPhone) {
//        return [NSStringFromCGSize([UIScreen mainScreen].bounds.size) isEqualToString:@"{375, 812}"];
//    }
    return MH_IS_IPHONE_X;
}

static inline CGFloat zh_topSafeAreaHeight () {
    return isIPhoneX() ? 44 : 0;
}

static inline CGFloat zh_safeAreaHeight () {
    return isIPhoneX() ? 34 : 0;
}

static inline NSString *FormatFloatToString(double f){
    if (fmodf(f, 1)==0) {//如果有一位小数点
        return [NSString stringWithFormat:@"%.0f",f];
    } else if (fmodf(f*10, 1)==0) {//如果有两位小数点
        return [NSString stringWithFormat:@"%.1f",f];
    } else {
        return [NSString stringWithFormat:@"%.2f",f];
    }
}

/// 适配
static inline CGFloat MHPxConvertToPt(CGFloat px){
    return ceil(px * [UIScreen mainScreen].bounds.size.width/350.0f);
}


static inline CGFloat MHTableViewFooterHeaderHeight(NSString *header){
    
    CGFloat limitWidth = MH_SCREEN_WIDTH - 2 * 20;
    CGFloat headerHeight = [header mh_sizeWithFont:MHRegularFont_14 limitWidth:limitWidth].height + 5 *2;
    return headerHeight;
}


static inline MHMomentMemberIdentity MHMemberIdentity(int32_t ownerId ,int32_t destId, int32_t  selfId){
    BOOL isOwner = selfId == ownerId ;
    if (isOwner) {
        return selfId == destId ? MHMomentOwnerToSelf:MHMomentOwnerToMember;
    }else
    {
        return selfId == destId ? MHMomentMemberToSelf:MHMomentMemberToOther;
    }
}


/// 辅助方法 创建一个文件夹
static inline void MHCreateDirectoryAtPath(NSString *path){
    BOOL isDir = NO;
    BOOL isExist = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir];
    if (isExist) {
        if (!isDir) {
            [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
            [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
        }
    } else {
        [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
    }
}
/// 微信重要数据备份的文件夹路径，通过NSFileManager来访问
static inline NSString *MHWeChatDocDirPath(){
    return [MHDocumentDirectory stringByAppendingPathComponent:MH_WECHAT_DOC_NAME];
}
/// 通过NSFileManager来获取指定重要数据的路径
static inline NSString *MHFilePathFromWeChatDoc(NSString *filename){
    NSString *docPath = MHWeChatDocDirPath();
    MHCreateDirectoryAtPath(docPath);
    return [docPath stringByAppendingPathComponent:filename];
}

/// 微信轻量数据备份的文件夹路径，通过NSFileManager来访问
static inline NSString *MHWeChatCacheDirPath(){
    return [MHCachesDirectory stringByAppendingPathComponent:MH_WECHAT_CACHE_NAME];
}
/// 通过NSFileManager来访问 获取指定轻量数据的路径
static inline NSString *MHFilePathFromWeChatCache(NSString *filename){
    NSString *cachePath = MHWeChatCacheDirPath();
    MHCreateDirectoryAtPath(cachePath);
    return [cachePath stringByAppendingPathComponent:filename];
}



#endif /* MHConstInline_h */
